import commonjs from "rollup-plugin-commonjs";
import resolve from "rollup-plugin-node-resolve";
// import babel from 'rollup-plugin-babel';
import uglify from "rollup-plugin-uglify";
import async from "rollup-plugin-async";
import { minify } from "uglify-es";

// `npm run build` -> `production` is true
// `npm run dev` -> `production` is false

const production = !process.env.ROLLUP_WATCH;
const inputs = ["rfs.js", "playground.js"];
const plugins = [
  commonjs({}),
  resolve({}),
  // babel({
  //   babelrc: false,
  //   runtimeHelpers: true,
  //   // use "module" field for ES6 module if possible
  //   'presets': [
  //     [
  //       "env",
  //       {
  //         "modules": false,
  //         "targets": {
  //           "browsers": ["last 2 versions"]
  //         }
  //       }
  //     ]
  //   ],
  //   'plugins': [
  //     "external-helpers", [
  //       "transform-runtime",
  //       {
  //         "polyfill": false,
  //         "regenerator": true
  //       }
  //     ]
  //   ],
  //   exclude: 'node_modules/**' // only transpile our source code
  // }),
  async(),
  production && uglify({}, minify) // minify, but only in production
];

export default (() => {
  return inputs.map(item => {
    return {
      input: "src/" + item,
      output: {
        file: "dist/" + item,
        format: "cjs", // immediately-invoked function expression — suitable for <script> tags
        sourcemap: false
      },
      plugins
    };
  });
})();
